<%@ page import="java.util.ArrayList" %>
<%@ page import="main_com.pojo.FileBean" %><%--
    Document   : fileDown
    Created on : 2012-3-21, 22:28:20
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body bgcolor="CCCFFF">
<%
    ArrayList<FileBean> files = (ArrayList<FileBean>) request.getSession().getAttribute("files");
%>
<hr noshade>
<div align="center">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
        <tr>
            <td width="20%">
                <a href="http://localhost/fileManager/fileUp.jsp">上传文件</a>
            </td>
            <td width="20%">
                文件列表
            </td>
        </tr>
    </table>
</div>
<hr noshade>
<br><br>
<%
    if (files == null || files.isEmpty()) {
%>
<div align="center">
    <h1>您还没有任何文件！</h1>
</div>
<%
} else {
%>
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
    <tr>
        <td>文件名</td>
        <td>标题</td>
        <td>大小</td>
        <td>类型</td>
        <td>删除</td>
    </tr>
        <%
            for(FileBean file : files) {
                %>
    <tr>
        <td>
            <a href="<%=file.getFilePath()%>" download="<%=file.getName()%>"><%=file.getName().split("\\.")[0]%>
            </a>
        </td>
        <td>
            <%=file.getTitle()%>
        </td>
        <td>
            <%
                long size = Long.parseLong(file.getSize());
                String[] d = {"字节", "KB", "MB", "GB"};
                for (int i = 0; i < 4; i++) {
                    if (size < 1024) {
                        out.println(size + d[i]);
                        break;
                    } else {
                        size /= 1024;
                    }
                }
            %>
        </td>
        <td>
            <%=file.getContentType()%>
        </td>
        <td><a href="http://localhost/FileDelController/fileDel?fileName=<%=file.getName()%>">删除</a></td>
    </tr>
        <%
            }
            out.println("</table>");
    }
    %>
</body>
</html>
